<template>
    <div class="page homeMore-page largeKanban-page" data-page="largeKanban">
        <div class="link-tab-page-top">
            <div class="link-tab-page-title">看板</div>
            <a href="#" class="link" id="bind-change-unit">
                <i class="iconfont icon-APPicon_shaixuan1
 search-select"></i>
            </a>
        </div>
        <div class="page-content home-content ptr-content" @ptr:refresh="refreshCards">
            <div class="ptr-preloader home-top-refresh" style="top: 30px;">
                <div class="preloader color-multi"></div>
                <div class="ptr-arrow"></div>
            </div>
            <!-- 首页卡片 -->
            <div class="cards-content unit-cards-content"></div>
            <!-- 首页页脚 -->
            <div class="bottom-custom-cards">
                <div class="set-custom-cards-btn bind-set-card">
                    <span class="iconfont icon-bianji1" style="font-size: 14px;margin-right: 2px;"></span>定制我的看板
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    return {
        data: function () {
            return {
                cardsList: [],  //定义接收的字段
                selectOptionOrg:'',
            }
        },
        methods: {
            backToRefresh: function () {
                var self = this;
                //common.loading(1);
                self.selectOptionOrg = '';
                single_Orgid = '';
                single_OrgName = '';
                platformCode = app.data.defaultPlatCode;
                if (!app.data.isFirstLoad) {
                    //重新绑定首页联网单位筛选的单位列表
                    getUnitListAndSave();
                }
            },
            //获取卡片数据
            getCards: function(){
                let self = this;
                let $ = self.$$;
                let orgId="";
                if(single_Orgid.toString().indexOf(",")==-1){
                    orgId=single_Orgid;
                }else{
                    orgId="";
                }
                Dao.unitStateList({
                    userName: userInfor.accountName,
                    deviceId: appKeyObj.deviceId,
                    userAccount: userInfor.accountName,
                    isMuilUnitUser: userInfor.isMuilUnitUser,
                    status: 1,
                    orgCode: platformCode || app.data.defaultPlatCode,
                    orgId:orgId
                }, function (data) {
                    self.cardsList = data;
                    globalCardList = data;
                    self.setCardDom(data);
                });
            },
            //设置卡片Dom
            setCardDom: function () {
                let self = this;
                let $ = self.$$;
                jQuery(".largeKanban-page .cards-content").empty();
                if (self.cardsList && self.cardsList.length > 0) {
                    for (let i = 0; i < self.cardsList.length; i++) {
                        $(".largeKanban-page .cards-content").append('<div class="view  card-view-style card-view-' + self.cardsList[i].id + '" id="muilPlat_' + self.cardsList[i].link + '" data-name="' + self.cardsList[i].link + '"></div>');
                    }
                    self.showEveryCards();
                }else{
                    $(".largeKanban-page .cards-content").append(`<div class="no-data-img" style="margin-top: 50%;"><img src='`+listNoDataPic()+`'/></div>`);
                }
            },
            //卡片嵌入页面
            showEveryCards: function () {
                let self = this;
                let $ = self.$$;
                if (self.cardsList && self.cardsList.length > 0) {
                    for (let i = 0; i < self.cardsList.length; i++) {
                        app.views.create('#muilPlat_' + self.cardsList[i].link, {url: '/' + self.cardsList[i].link + '/'});
                    }
                }
            },
            //刷新
            refreshCards: function (e, done) {
                let self = this;
                let $ = self.$$;
                if(1 === e){
                    common.loading(1);
                }else{
                    $(".home-top-refresh").show();
                }
                if (done && e) {
                    setTimeout(function () {
                        self.getCards();
                        done();
                        if(1 === e){
                            common.loading(0);
                        }else{
                            $(".home-top-refresh").hide();
                        }
                    },1000);
                }
            },
            //绑定事件
            initBind:function(){
                let self = this;
                //联网单位
                jQuery("#bind-change-unit").off().click(function () {
                    loadSelectUnitFunc(function(data){
                        //选中
                        if(self.selectOptionOrg != data.orgId){
                            self.selectOptionOrg = data.orgId;
                            single_Orgid = data.orgId;
                            single_OrgName = data.orgName;
                            self.loadSingle();
                        } else {
                            /* jQuery(".bottom-custom-cards").show();
                            self.selectOptionOrg = "";
                            self.getCards(); */
                        }
                    },self.selectOptionOrg);
                });

                //定制
                jQuery(".bind-set-card").click(function(event) {
                    app.router.navigate("/editCard/");
                });
            },
            //载入单单位页面
            loadSingle:function(){
                let self = this;
                app.router.navigate("/soleKanban/")
            },
            //多平台去子平台
            morePlatToSingle:function(orgIds, platName){
                var self = this;
                common.loading(1);
                single_Orgid = orgIds
                single_OrgName = platName;
                setTimeout(function(){
                    app.router.navigate("/largeKanban_singlePlat/")
                    common.loading(0)
                },1200);
            },
        },
        on: {
            pageInit: function (e, page) {
                let self = this;
                if (self.cardsList.length == 0) {
                    common.loading(1);
                    self.getCards();
                    self.initBind();
                    setTimeout(function () {
                        common.loading(0);
                    }, 1000);
                    window.getCards_largeKanban = self.refreshCards;
                }
                //最后一个page进入的时候
                if(self.cardsList.length > 0){
                    //刚进入页面
                    if(self.cardsList[self.cardsList.length-1].link == page.route.name){
                        //绑定事件
                        self.initBind();
                    }
                }
                if(app.data.isFirstLoad){
                    app.data.isFirstLoad=false;
                    getPublicReouse();
                }

            },

        }
    }
</script>
<style>
    .link-tab-page-top .link-tab-page-title{
        font-weight: bold;
    }
</style>